package com.bamanker.cloudapi.model.exception;

import com.bamanker.cloudapi.model.response.ResultCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author bamanker
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseException extends RuntimeException {
    /**
     * 返回码
     */
    protected ResultCode resultCode;
    /**
     * 异常消息参数
     */
    protected Object[] args;

    public BaseException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.resultCode = resultCode;
    }


    public BaseException(String code, String msg) {
        super(msg);
        this.resultCode = new ResultCode() {
            @Override
            public String getCode() {
                return code;
            }

            @Override
            public String getMessage() {
                return msg;
            }

            @Override
            public boolean getSuccess() {
                return false;
            }

            ;
        };
    }

    public BaseException(ResultCode resultCode, Object[] args, String message) {
        super(message);
        this.resultCode = resultCode;
        this.args = args;
    }

    public BaseException(ResultCode resultCode, Object[] args, String message, Throwable cause) {
        super(message, cause);
        this.resultCode = resultCode;
        this.args = args;
    }

}